package com.javasm.springmybatis.async;

import com.javasm.springmybatis.common.util.SpringContainerUtils;
import com.javasm.springmybatis.task.MyTask;
import com.sun.org.apache.regexp.internal.RE;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

/**
 * @Author：xieyunfan
 * @Version：1.0
 * @Date：2021/12/31-23:51
 * @Since:jdk1.8
 * @Description:
 */
//感觉就是所有耗时操作都封装成方法
//@Component
public class AsyncFactory {

    //为什么这里使用不了  一直是空指针异常
//    @Autowired
//    public static JavaMailSender javaMailSender;


    //封装
    //返回runnnble对象
    public static Runnable sendEmail(String email, String code) {
        Runnable runnable = () -> {
            System.out.println(Thread.currentThread().getName());
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            simpleMailMessage.setFrom("谢闯<xyunf1010@163.com>");
            simpleMailMessage.setSubject("验证码");
            simpleMailMessage.setText(code);
            simpleMailMessage.setTo(email);
            JavaMailSender javaMailSender = SpringContainerUtils.getBean(JavaMailSender.class);
            javaMailSender.send(simpleMailMessage);
        };
        return runnable;
    }

}
